package com.qingtian;

import org.jodconverter.DocumentConverter;
import org.jodconverter.LocalConverter;
import org.jodconverter.office.LocalOfficeManager;
import org.jodconverter.office.OfficeException;
import org.jodconverter.office.OfficeManager;

import java.io.File;

/**
 * @Author qingtian
 * @Description word转pdf
 * @Date Created in 2018/4/10
 */
public class WordToPdf {

    private static final String INPUT_DOCX_FILE = "src/main/resources/input/word_to_pdf.docx";

    private static final String OUTPUT_DOCX_PDF_FILE = "src/main/resources/output/test.pdf";

    public static void main(String[] args) throws OfficeException {

        OfficeManager officeManager = LocalOfficeManager.make();
        DocumentConverter converter = LocalConverter.make(officeManager);
        officeManager.start();
        try {
            System.out.println("convert start");

            File doc = new File(INPUT_DOCX_FILE);
            File pdf = new File(OUTPUT_DOCX_PDF_FILE);
            converter.convert(doc).to(pdf).execute();

            System.out.println("convert end");
        } finally {
            officeManager.stop();
        }
    }
}
